package com.fzy.designpattern.memento;

/**
 * 需要备忘的业务实体类
 *
 * @author 冯赵杨
 * @create 2018/9/14
 */
public class Student {

    private String name;
    private int age;

    /**
     * 数据保存，备忘
     *
     * @return
     */
    public StudentMemento memento() {
        StudentMemento sm = new StudentMemento();
        sm.setName(this.name);
        sm.setAge(this.age);
        return sm;
    }


    /**
     * 数据恢复
     *
     * @param sm 备忘的消息实体，属性基本和student一致，便于拷贝
     */
    public void recovery(StudentMemento sm) {

        this.name = sm.getName();
        this.age = sm.getAge();

    }


    public Student(String name, int age) {
        super();
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        System.out.println("name = " + name + " age = " + age);
        return super.toString();
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

}